/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package entity;

import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author antonio
 */
@Entity
@Table(name = "Cost")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Cost.findAll", query = "SELECT c FROM Cost c"),
    @NamedQuery(name = "Cost.findByResource", query = "SELECT c FROM Cost c WHERE c.costPK.resource = :resource"),
    @NamedQuery(name = "Cost.findByConstruct", query = "SELECT c FROM Cost c WHERE c.costPK.construct = :construct"),
    @NamedQuery(name = "Cost.findByAmount", query = "SELECT c FROM Cost c WHERE c.amount = :amount")})
public class Cost implements Serializable {

    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected CostPK costPK;
    @Basic(optional = false)
    @NotNull
    @Column(name = "amount")
    private int amount;
    @JoinColumn(name = "construct", referencedColumnName = "name", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Construct construct1;
    @JoinColumn(name = "resource", referencedColumnName = "name", insertable = false, updatable = false)
    @ManyToOne(optional = false)
    private Resource resource1;

    public Cost() {
    }

    public Cost(CostPK costPK) {
        this.costPK = costPK;
    }

    public Cost(CostPK costPK, int amount) {
        this.costPK = costPK;
        this.amount = amount;
    }

    public Cost(String resource, String construct) {
        this.costPK = new CostPK(resource, construct);
    }

    public CostPK getCostPK() {
        return costPK;
    }

    public void setCostPK(CostPK costPK) {
        this.costPK = costPK;
    }

    public int getAmount() {
        return amount;
    }

    public void setAmount(int amount) {
        this.amount = amount;
    }

    public Construct getConstruct1() {
        return construct1;
    }

    public void setConstruct1(Construct construct1) {
        this.construct1 = construct1;
    }

    public Resource getResource1() {
        return resource1;
    }

    public void setResource1(Resource resource1) {
        this.resource1 = resource1;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (costPK != null ? costPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Cost)) {
            return false;
        }
        Cost other = (Cost) object;
        if ((this.costPK == null && other.costPK != null) || (this.costPK != null && !this.costPK.equals(other.costPK))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "entity.Cost[ costPK=" + costPK + " ]";
    }
}
